//index.js
//获取应用实例
const app = getApp()
Page({
  data: {
    username: '',
    password: '',
    head_pic: ''

  },
  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      //url: '../logs/logs'
    })
  },
  onShow: function () {
    // 生命周期函数--监听页面显示
    wx.hideTabBar({})
  },
  onLoad: function () {
  },
  // 获取输入账号 
  usernameInput: function (e) {
    this.setData({
      username: e.detail.value
    })
  },
  // 获取输入密码 
  passwordInput: function (e) {
    this.setData({
      password: e.detail.value
    })
  },
  // 登录处理
  login: function () {
    var that = this;
    if (this.data.username.length == 0 || this.data.password.length == 0) {
      wx.showToast({
        title: '账号或密码不能为空',
        icon: 'none',
        duration: 2000
      })
    } else {
      wx.showLoading({
        title: '请稍等',
      });
      wx.request({
        url: 'http://localhost:8080/login_do2', // 仅为示例，并非真实的接口地址
        method: 'post',
        data: {
          username: that.data.username,
          password: that.data.password
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        success(res) {
          wx.hideLoading();
          console.info(res.data);
          if (res.data == "true") {
            //  wx.setStorageSync('token', res.data.data.token);//token
            //  wx.setStorageSync('account', res.data.data.account);
            wx.switchTab({
              url: '../home/home'
            })
          } 
        }

      })
    }
  }
})